/*
ID: pallab81
PROG:
LANG: C++
*/

//"I have not failed, I have just found 10000 ways that won't work.

#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstdlib>

using namespace std;

#define VI vector< int >
#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define foR(i1,st,ed) for(int i1 = st,j1 = ed ; i1 < j1 ; ++i1 )
#define fo(i,ed) foR( i , 0 , ed )
#define foE(i,st,ed) foR( i , st , ed+1 )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip( X ) sleep( X )
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )

class RookAttack {
public:
    int howMany(int rows, int cols, vector <string> cutouts);
};

inline pair<int,int> _split(string str) {
    int a,b;
    sscanf(str.c_str(),"%d %d",&a,&b);
    return mk( a, b );
}
const int maxn = (300*2)+2;
int N;
int cap[maxn+2][maxn+2];
int used[ maxn+2 ];
int from[ maxn+2 ];

inline int bfs(int source, int sink) {
    queue< int > Q;
    SET(used,0);
    SET(from,-1);

    used[ source ]=1;
    Q.push( source );

    while ( !Q.empty() ) {
        int where = Q.front();
        Q.pop();
        for (int next=0;next<=sink;++next) {
            if ( cap[ where][ next ]>0 && !used[next] ) {
                used[ next ]=1;
                from[ next ]=where;
                Q.push( next );
                if ( next==sink ) {
                    goto L;
                }
            }
        }
    }
L :
    ;
    if ( from[ sink ]==-1 ) {
        return 0;
    }

    int where = sink, pathcap = (int)1023456789;
    while ( from[ where ] != -1 ) {
        int prev = from[ where ];
        pathcap = min( pathcap, cap[ prev ][ where ] );
        where = prev;
    }
    where = sink;
    while ( from[ where ] != -1 ) {
        int prev = from[ where ];
        cap[ prev ][ where ]-= pathcap;
        cap[ where][ prev  ]+= pathcap;
        where = prev;
    }

    return 1;

}
inline int maxflow(int source, int sink) {
    int maxf=0;
    while (true) {
        int path_cap = bfs(source, sink );
        if ( path_cap==0 ) {
            break;
        }
        maxf+=path_cap;
    }
    return maxf;
}
int RookAttack :: howMany(int rows, int cols, vector <string> cutouts) {
    N = rows+cols;
    fo(i,rows) {
        fo(j,cols) {
            cap[i][ rows+j ]=1;
        }
    }
    fo(i,SZ(cutouts)) {
        stringstream ss(cutouts[i]);
        for (string tmp; getline(ss,tmp,','); ) {
            if ( LN(tmp)<1 )continue;
            pair<int,int> A = _split( tmp );
            cap[ A.first ][ rows+A.second ] = 0;
        }

    }
    int source = N;
    int sink = N+1;

    fo(i,rows) {
        cap[source][i]=1;
    }
    fo(j,cols) {
        cap[rows+j][sink]=1;
    }

    int var = maxflow(source, sink);
    return var;
}
// BEGIN KAWIGIEDIT TESTING
// Generated by KawigiEdit 2.1.8 (beta) modified by pivanof
#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool KawigiEdit_RunTest(int testNum, int p0, int p1, vector <string> p2, bool hasAnswer, int p3) {
    cout << "Test " << testNum << ": [" << p0 << "," << p1 << "," << "{";
    for (int i = 0; int(p2.size()) > i; ++i) {
        if (i > 0) {
            cout << ",";
        }
        cout << "\"" << p2[i] << "\"";
    }
    cout << "}";
    cout << "]" << endl;
    RookAttack *obj;
    int answer;
    obj = new RookAttack();
    clock_t startTime = clock();
    answer = obj->howMany(p0, p1, p2);
    clock_t endTime = clock();
    delete obj;
    bool res;
    res = true;
    cout << "Time: " << double(endTime - startTime) / CLOCKS_PER_SEC << " seconds" << endl;
    if (hasAnswer) {
        cout << "Desired answer:" << endl;
        cout << "\t" << p3 << endl;
    }
    cout << "Your answer:" << endl;
    cout << "\t" << answer << endl;
    if (hasAnswer) {
        res = answer == p3;
    }
    if (!res) {
        cout << "DOESN'T MATCH!!!!" << endl;
    } else if (double(endTime - startTime) / CLOCKS_PER_SEC >= 2) {
        cout << "FAIL the timeout" << endl;
        res = false;
    } else if (hasAnswer) {
        cout << "Match :-)" << endl;
    } else {
        cout << "OK, but is it right?" << endl;
    }
    cout << "" << endl;
    return res;
}
int main() {
    bool all_right;
    all_right = true;

    int p0;
    int p1;
    vector <string> p2;
    int p3;

    {
        // ----- test 0 -----
        p0 = 8;
        p1 = 8;
        p2.clear() /*{}*/;
        p3 = 8;
        all_right = KawigiEdit_RunTest(0, p0, p1, p2, true, p3) && all_right;
        // ------------------
    }

    {
        // ----- test 1 -----
        p0 = 2;
        p1 = 2;
        string t2[] = {"0 0","0 1","1 1","1 0"};
        p2.assign(t2, t2 + sizeof(t2) / sizeof(t2[0]));
        p3 = 0;
        all_right = KawigiEdit_RunTest(1, p0, p1, p2, true, p3) && all_right;
        // ------------------
    }

    {
        // ----- test 2 -----
        p0 = 3;
        p1 = 3;
        string t2[] = {"0 0","1 0","1 1","2 0","2 1","2 2"};
        p2.assign(t2, t2 + sizeof(t2) / sizeof(t2[0]));
        p3 = 2;
        all_right = KawigiEdit_RunTest(2, p0, p1, p2, true, p3) && all_right;
        // ------------------
    }

    {
        // ----- test 3 -----
        p0 = 3;
        p1 = 3;
        string t2[] = {"0 0","1 2","2 2"};
        p2.assign(t2, t2 + sizeof(t2) / sizeof(t2[0]));
        p3 = 3;
        all_right = KawigiEdit_RunTest(3, p0, p1, p2, true, p3) && all_right;
        // ------------------
    }

    {
        // ----- test 4 -----
        p0 = 200;
        p1 = 200;
        p2.clear() /*{}*/;
        p3 = 200;
        all_right = KawigiEdit_RunTest(4, p0, p1, p2, true, p3) && all_right;
        // ------------------
    }

    if (all_right) {
        cout << "You're a stud (at least on the example cases)!" << endl;
    } else {
        cout << "Some of the test cases had errors." << endl;
    }
    return 0;
}
// END KAWIGIEDIT TESTING
//Powered by KawigiEdit 2.1.8 (beta) modified by pivanof!
// kate: indent-mode cstyle; space-indent on; indent-width 0; 


